package com.tea.app.moudles.controller;

import com.tea.app.moudles.entity.GoodsCollection;
import com.tea.app.moudles.service.GoodsCollectionService;
import com.tea.common.common.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/collection")
public class GoodsCollectionController {

    @Autowired
    private GoodsCollectionService collectionService;

    @PostMapping("/add")
    public Result<Void> addCollection(@RequestBody Map<String, Object> params) {
        String wxOpenid = (String) params.get("wxOpenid");
        Long goodsId = Long.valueOf(params.get("goodsId").toString());
        collectionService.addCollection(wxOpenid, goodsId);
        return Result.ok();
    }

    @DeleteMapping("/remove")
    public Result<Void> removeCollection(@RequestBody Map<String, Object> params) {
        String wxOpenid = (String) params.get("wxOpenid");
        Long goodsId = Long.valueOf(params.get("goodsId").toString());

        collectionService.removeCollection(wxOpenid, goodsId);
        return Result.ok();
    }

    @GetMapping("/list")
    public Result<List<GoodsCollection>> getUserCollections(@RequestParam String wxOpenid) {
        return Result.ok(collectionService.getUserCollections(wxOpenid));
    }

    @GetMapping("/ids")
    public Result<List<Long>> getUserCollectionGoodsIds(@RequestParam String wxOpenid) {
        return Result.ok(collectionService.getUserCollectionGoodsIds(wxOpenid));
    }
}